package com.example.huainanlive.ui

import android.os.Bundle
import android.view.View
import com.demon.androidbasic.base.MyActivity
import com.example.huainanlive.databinding.ActivityMainBinding
import com.qiniu.qmedia.component.player.QMediaModelBuilder
import com.qiniu.qmedia.component.player.QPlayerSetting
import com.qiniu.qmedia.component.player.QURLType


class MainActivity : MyActivity<ActivityMainBinding>() {

    override fun initBind() {
        binding = ActivityMainBinding.inflate(inflater)

    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding.playerView.let {mQSurfacePlayerView->
            mQSurfacePlayerView.playerControlHandler.init(this)
            mQSurfacePlayerView.playerControlHandler.setDecodeType(QPlayerSetting.QPlayerDecoder.QPLAYER_DECODER_SETTING_SOFT_PRIORITY)
            mQSurfacePlayerView.playerControlHandler.setSeekMode(QPlayerSetting.QPlayerSeek.QPLAYER_SEEK_SETTING_NORMAL)
            mQSurfacePlayerView.playerControlHandler.setStartAction(QPlayerSetting.QPlayerStart.QPLAYER_START_SETTING_PLAYING)
            mQSurfacePlayerView.playerControlHandler.setSpeed(1.0F)

        }

    }

    override fun initView() {

        binding.playerView.visibility = View.VISIBLE
        val builder = QMediaModelBuilder()
        // TODO 我们正式开发的url  http://stream.0554news.com/hnds1/playlist.m3u8?_upt=cc441e8f1669371377
        // TODO 七牛提供的的url  http://demo-videos.qnsdk.com/movies/qiniu.mp4
        val url = "http://demo-videos.qnsdk.com/movies/qiniu.mp4"
        builder.addElement("", QURLType.QAUDIO_AND_VIDEO, 1080, url, true)
        val mediaModel = builder.build(true)


        binding.bt.setOnClickListener{
            LiveHousePreviewActivity.forward(this)
//            binding.playerView.playerControlHandler.playMediaModel(mediaModel, 0)

        }

        binding.bt2.setOnClickListener{
            LiveHouseRecordActivity.forward(this)
        }


    }

    override fun onDestroy() {
        binding.playerView.playerControlHandler.release()

        super.onDestroy()
    }
}